package com.item.service.impl;

import com.github.pagehelper.PageHelper;
import com.item.domain.TbUserComment;
import com.item.mapper.TbUserCommentMapper;
import com.item.service.TbUserCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbUserCommentServiceImpl implements TbUserCommentService {

    @Autowired
    TbUserCommentMapper tbUserCommentMapper;


    public List<TbUserComment> findAll(int limit, int page, TbUserComment tbUserComment) {
        if (limit > 0 && page > 0) {
            PageHelper.startPage(limit, page);
        }
        return tbUserCommentMapper.findAll(tbUserComment);
    }


    public int add(TbUserComment tbUserComment) {
        String images = tbUserComment.getImages();
        String substring = images.substring(0, images.length() - 1);
        tbUserComment.setImages(substring);
        return tbUserCommentMapper.insertSelective(tbUserComment);
    }


    public int update(TbUserComment tbUserComment) {
        return tbUserCommentMapper.updateByPrimaryKey(tbUserComment);
    }

    @Override
    public int delete(int id) {
        return tbUserCommentMapper.deleteByPrimaryKey(id);
    }
}
